{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "85edd6bf",
   "metadata": {},
   "source": [
    "# 安装 rust版的jupyter"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1faa83d7",
   "metadata": {},
   "source": [
    "## 参考"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3bd8354",
   "metadata": {},
   "source": [
    "- evcxr项目： https://github.com/evcxr/evcxr\n",
    "- 原文：https://github.com/evcxr/evcxr/blob/main/evcxr_jupyter/README.md"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c141b11b",
   "metadata": {},
   "source": [
    "## 安装\n",
    "\n",
    "如果你还没有安装 [Rust](coco://sendMessage?ext=%7B%22s%24wiki_link%22%3A%22https%3A%2F%2Fm.baike.com%2Fwikiid%2F6243263002994682886%22%7D&msg=Rust)，[请遵循这些说明](https://www.rust-lang.org/tools/install)。\n",
    "\n",
    "你可以从[发布版](https://github.com/evcxr/evcxr/releases)页面下载预构建的二进制文件，从归档文件中提取它，并将其放在你的路径上的某个位置，或者通过运行以下命令从源代码构建：\n",
    "\n",
    "\n",
    "```sh\n",
    "cargo install --locked evcxr_jupyter\n",
    "```\n",
    "\n",
    "无论是使用预构建的二进制文件还是你自己构建的二进制文件，你都需要运行以下命令以便将内核与 Jupyter 注册。\n",
    "\n",
    "\n",
    "```sh\n",
    "evcxr_jupyter --install\n",
    "```\n",
    "\n",
    "默认情况下，`evcxr_jupyter --install` 将把内核安装到用户本地目录，例如，`$HOME/.local/share/jupyter/kernels`。\n",
    "\n",
    "如果你的操作系统是较旧的版本，或者具有与预构建的二进制文件编译时不同的 libc，那么你需要使用上面的命令从源代码构建。\n",
    "\n",
    "要实际使用 evcxr_jupyter，你需要安装 Jupyter 笔记本。\n",
    "\n",
    "* Debian 或 Ubuntu Linux：`sudo apt install jupyter-notebook`\n",
    "* Mac：你可能可以 `brew install jupyter`\n",
    "* Windows，或者如果上述选项对你不起作用，请参见 [https://jupyter.org/install](https://jupyter.org/install)\n",
    "\n",
    "你还需要安装 Rust 标准库的源代码。如果你已经使用了 rust-analyzer，你可能已经安装了它。要使用 rustup 安装此源代码，请运行：\n",
    "\n",
    "\n",
    "\n",
    "```sh\n",
    "rustup component add rust-src\n",
    "```\n",
    "\n",
    "## 运行\n",
    "\n",
    "要启动 Jupyter Notebook，运行：\n",
    "\n",
    "\n",
    "\n",
    "```sh\n",
    "jupyter notebook\n",
    "```\n",
    "\n",
    "一旦启动，它应该会在你的网络浏览器中打开一个页面。在右侧查找“新建”菜单，并从其中选择“Rust”。\n",
    "\n",
    "## 使用信息\n",
    "\n",
    "Evcxr 既是一个 REPL，也是一个 Jupyter 内核。有关两者通用的信息，请参见 [Evcxr 常见用法](https://github.com/evcxr/evcxr/blob/main/COMMON.md)。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "88241d6b",
   "metadata": {},
   "source": [
    "## 使用示例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1b4aaabd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"hello\""
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fn hello() -> String {\n",
    "    return \"hello\".to_string()\n",
    "}\n",
    "\n",
    "hello()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2bb9c39a",
   "metadata": {},
   "outputs": [],
   "source": [
    ":dep rand = { version = \"0.7.3\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "96213b69",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "217"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "let r: u8 = rand::random();\n",
    "r"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Rust",
   "language": "rust",
   "name": "rust"
  },
  "language_info": {
   "codemirror_mode": "rust",
   "file_extension": ".rs",
   "mimetype": "text/rust",
   "name": "Rust",
   "pygment_lexer": "rust",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
